package com.ruoyi.project.yuwen.audioblack.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.yuwen.audioblack.domain.AudioBlack;
import com.ruoyi.project.yuwen.audioblack.service.IAudioBlackService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 封禁用户Controller
 * 
 * @author shixiangwen
 * @date 2021-02-24
 */
@Controller
@RequestMapping("/yuwen/audioblack")
public class AudioBlackController extends BaseController
{
    private String prefix = "yuwen/audioblack";

    @Autowired
    private IAudioBlackService audioBlackService;

    @RequiresPermissions("yuwen:audioblack:view")
    @GetMapping()
    public String audioblack()
    {
        return prefix + "/audioblack";
    }

    /**
     * 查询封禁用户列表
     */
    @RequiresPermissions("yuwen:audioblack:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(AudioBlack audioBlack)
    {
        startPage();
        List<AudioBlack> list = audioBlackService.selectAudioBlackList(audioBlack);
        return getDataTable(list);
    }

    /**
     * 导出封禁用户列表
     */
    @RequiresPermissions("yuwen:audioblack:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(AudioBlack audioBlack)
    {
        List<AudioBlack> list = audioBlackService.selectAudioBlackList(audioBlack);
        ExcelUtil<AudioBlack> util = new ExcelUtil<AudioBlack>(AudioBlack.class);
        return util.exportExcel(list, "audioblack");
    }

    /**
     * 新增封禁用户
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存封禁用户
     */
    @RequiresPermissions("yuwen:audioblack:add")
    @Log(title = "封禁用户", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(AudioBlack audioBlack)
    {
        return toAjax(audioBlackService.insertAudioBlack(audioBlack));
    }

    /**
     * 修改封禁用户
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        AudioBlack audioBlack = audioBlackService.selectAudioBlackById(id);
        mmap.put("audioBlack", audioBlack);
        return prefix + "/edit";
    }

    /**
     * 修改保存封禁用户
     */
    @RequiresPermissions("yuwen:audioblack:edit")
    @Log(title = "封禁用户", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(AudioBlack audioBlack)
    {
        return toAjax(audioBlackService.updateAudioBlack(audioBlack));
    }

    /**
     * 删除封禁用户
     */
    @RequiresPermissions("yuwen:audioblack:remove")
    @Log(title = "封禁用户", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(audioBlackService.deleteAudioBlackByIds(ids));
    }
}
